Sang Yeol Lee
August 25 2017
General Tips for participating Kaggle Competitions, Mark Peng, Taiwan Kaggle Master
일반적인 캐글의 데이터 셋은 Train set, Test Set으로 나뉨 (Submission 파일이 따로 있음)
Test Set은 대회 기간 동안 제출하면 채점 용도로 공개되어 있는 Public LB(Leardboard)와 대회 끝난 후 최종 채점을 평가하는 Private LB(Leardboard)가 있음
물론 데이터 셋이 일반적이지 않을 수 있음
대회의 목적(상금, 직업, 지식 공유…)에 따라서 문제가 달라짐.
캐글 프로세스는 데이터 분석의 절차 (서비스의 직접 반영하진 않지만, 커뮤니케이션은 포럼의 참가자들과 Kernel에서 Notebook 형태로 공유)
1단계 데이터 전처리, 2단계 싱글 모델, 3단계 변수 구성, 4단계 탐색적 자료 분석, 5단계 다양한 모델 구성, 6단계 앙상블, 7단계 예측
데이터 전처리
싱글 모델
변수 구성
탐색적 자료 분석
다양한 모델 구성
앙상블
제출
precision, Recall(sensitivity) Example (Hands on ML with Sciki-learn with Tensorflow 책 발췌)
모델을 구성할 때 Bias-Variance Trade off 관계에 있음
몸무게 = Beta 0 + 키 * Beta1 + 키2 * Beta2 + 키3 * Beta3… + 키8 + Beta8 일거야.
어떤 모델이든 Underfitting 하거나 Overfitting 할 수 있음, 적정선을 찾아야 함.
주로 Train 데이터를 Validaton 하여 해당 에러와 Test 에러를 같이 확인
Test Error를 보기 전에 평가 함수를 구성하여 Validation Error를 확인하는 것이 핵심! (Cross Validation, Local CV)
K-Fold Cross Validation (K=5)
균일하게 K 갯수만큼 Train 데이터를 쪼갬. k=5이면 5개로 쪼개서, Round 1~5번까지 Train data의 80%를 모델 구성하는데 사용하고 20%를 Validation 하는 데 사용, 해당 작업을 5번 거쳐서 평균 cv를 구하여 모델을 평가
local CV와 Public LB 간의 갭 차이가 나는 K를 찾는 것이 팁. 데이터가 Imbalance 되어 있다면 Stratified K-fold cv(목표변수의 클래스 비율을 똑같이 구성하여 쪼개는 방법)를 구성하라고 추천하고 있음

Ask a home buyer to describe their dream house
With 79 explanatory variables describing (almost) every aspect of residential homes in Ames, Iowa, this competition challenges you to predict the final price of each home.
Here's a brief version of what you'll find in the data description file.
Id,SalePrice
1461,169000.1
1462,187724.1233
1463,175221
etc.
후보 주제(1) : Web Traffic Time Series Forecasting
후보 주제(2) : New York City Taxi Trip Duration
후보 주제(3) : Zillow Prize: Zillow’s Home Value Prediction
library(tidyverse)
#ref1 : https://www.kaggle.com/notaapple/detailed-exploratory-data-analysis-using-r
#ref2 : https://www.kaggle.com/jiashenliu/house-prices-advanced-regression-techniques/updated-xgboost-with-parameter-tuning/run/362252
train <- read_csv('./data/train.csv')
colnames(train)
[1] "Id" "MSSubClass" "MSZoning" "LotFrontage"
[5] "LotArea" "Street" "Alley" "LotShape"
[9] "LandContour" "Utilities" "LotConfig" "LandSlope"
[13] "Neighborhood" "Condition1" "Condition2" "BldgType"
[17] "HouseStyle" "OverallQual" "OverallCond" "YearBuilt"
[21] "YearRemodAdd" "RoofStyle" "RoofMatl" "Exterior1st"
[25] "Exterior2nd" "MasVnrType" "MasVnrArea" "ExterQual"
[29] "ExterCond" "Foundation" "BsmtQual" "BsmtCond"
[33] "BsmtExposure" "BsmtFinType1" "BsmtFinSF1" "BsmtFinType2"
[37] "BsmtFinSF2" "BsmtUnfSF" "TotalBsmtSF" "Heating"
[41] "HeatingQC" "CentralAir" "Electrical" "1stFlrSF"
[45] "2ndFlrSF" "LowQualFinSF" "GrLivArea" "BsmtFullBath"
[49] "BsmtHalfBath" "FullBath" "HalfBath" "BedroomAbvGr"
[53] "KitchenAbvGr" "KitchenQual" "TotRmsAbvGrd" "Functional"
[57] "Fireplaces" "FireplaceQu" "GarageType" "GarageYrBlt"
[61] "GarageFinish" "GarageCars" "GarageArea" "GarageQual"
[65] "GarageCond" "PavedDrive" "WoodDeckSF" "OpenPorchSF"
[69] "EnclosedPorch" "3SsnPorch" "ScreenPorch" "PoolArea"
[73] "PoolQC" "Fence" "MiscFeature" "MiscVal"
[77] "MoSold" "YrSold" "SaleType" "SaleCondition"
[81] "SalePrice"
glimpse(train)
Observations: 1,460
Variables: 81
$ Id <int> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 1...
$ MSSubClass <int> 60, 20, 60, 70, 60, 50, 20, 60, 50, 190, 20, 60,...
$ MSZoning <chr> "RL", "RL", "RL", "RL", "RL", "RL", "RL", "RL", ...
$ LotFrontage <int> 65, 80, 68, 60, 84, 85, 75, NA, 51, 50, 70, 85, ...
$ LotArea <int> 8450, 9600, 11250, 9550, 14260, 14115, 10084, 10...
$ Street <chr> "Pave", "Pave", "Pave", "Pave", "Pave", "Pave", ...
$ Alley <chr> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, ...
$ LotShape <chr> "Reg", "Reg", "IR1", "IR1", "IR1", "IR1", "Reg",...
$ LandContour <chr> "Lvl", "Lvl", "Lvl", "Lvl", "Lvl", "Lvl", "Lvl",...
$ Utilities <chr> "AllPub", "AllPub", "AllPub", "AllPub", "AllPub"...
$ LotConfig <chr> "Inside", "FR2", "Inside", "Corner", "FR2", "Ins...
$ LandSlope <chr> "Gtl", "Gtl", "Gtl", "Gtl", "Gtl", "Gtl", "Gtl",...
$ Neighborhood <chr> "CollgCr", "Veenker", "CollgCr", "Crawfor", "NoR...
$ Condition1 <chr> "Norm", "Feedr", "Norm", "Norm", "Norm", "Norm",...
$ Condition2 <chr> "Norm", "Norm", "Norm", "Norm", "Norm", "Norm", ...
$ BldgType <chr> "1Fam", "1Fam", "1Fam", "1Fam", "1Fam", "1Fam", ...
$ HouseStyle <chr> "2Story", "1Story", "2Story", "2Story", "2Story"...
$ OverallQual <int> 7, 6, 7, 7, 8, 5, 8, 7, 7, 5, 5, 9, 5, 7, 6, 7, ...
$ OverallCond <int> 5, 8, 5, 5, 5, 5, 5, 6, 5, 6, 5, 5, 6, 5, 5, 8, ...
$ YearBuilt <int> 2003, 1976, 2001, 1915, 2000, 1993, 2004, 1973, ...
$ YearRemodAdd <int> 2003, 1976, 2002, 1970, 2000, 1995, 2005, 1973, ...
$ RoofStyle <chr> "Gable", "Gable", "Gable", "Gable", "Gable", "Ga...
$ RoofMatl <chr> "CompShg", "CompShg", "CompShg", "CompShg", "Com...
$ Exterior1st <chr> "VinylSd", "MetalSd", "VinylSd", "Wd Sdng", "Vin...
$ Exterior2nd <chr> "VinylSd", "MetalSd", "VinylSd", "Wd Shng", "Vin...
$ MasVnrType <chr> "BrkFace", "None", "BrkFace", "None", "BrkFace",...
$ MasVnrArea <int> 196, 0, 162, 0, 350, 0, 186, 240, 0, 0, 0, 286, ...
$ ExterQual <chr> "Gd", "TA", "Gd", "TA", "Gd", "TA", "Gd", "TA", ...
$ ExterCond <chr> "TA", "TA", "TA", "TA", "TA", "TA", "TA", "TA", ...
$ Foundation <chr> "PConc", "CBlock", "PConc", "BrkTil", "PConc", "...
$ BsmtQual <chr> "Gd", "Gd", "Gd", "TA", "Gd", "Gd", "Ex", "Gd", ...
$ BsmtCond <chr> "TA", "TA", "TA", "Gd", "TA", "TA", "TA", "TA", ...
$ BsmtExposure <chr> "No", "Gd", "Mn", "No", "Av", "No", "Av", "Mn", ...
$ BsmtFinType1 <chr> "GLQ", "ALQ", "GLQ", "ALQ", "GLQ", "GLQ", "GLQ",...
$ BsmtFinSF1 <int> 706, 978, 486, 216, 655, 732, 1369, 859, 0, 851,...
$ BsmtFinType2 <chr> "Unf", "Unf", "Unf", "Unf", "Unf", "Unf", "Unf",...
$ BsmtFinSF2 <int> 0, 0, 0, 0, 0, 0, 0, 32, 0, 0, 0, 0, 0, 0, 0, 0,...
$ BsmtUnfSF <int> 150, 284, 434, 540, 490, 64, 317, 216, 952, 140,...
$ TotalBsmtSF <int> 856, 1262, 920, 756, 1145, 796, 1686, 1107, 952,...
$ Heating <chr> "GasA", "GasA", "GasA", "GasA", "GasA", "GasA", ...
$ HeatingQC <chr> "Ex", "Ex", "Ex", "Gd", "Ex", "Ex", "Ex", "Ex", ...
$ CentralAir <chr> "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y"...
$ Electrical <chr> "SBrkr", "SBrkr", "SBrkr", "SBrkr", "SBrkr", "SB...
$ 1stFlrSF <int> 856, 1262, 920, 961, 1145, 796, 1694, 1107, 1022...
$ 2ndFlrSF <int> 854, 0, 866, 756, 1053, 566, 0, 983, 752, 0, 0, ...
$ LowQualFinSF <int> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ...
$ GrLivArea <int> 1710, 1262, 1786, 1717, 2198, 1362, 1694, 2090, ...
$ BsmtFullBath <int> 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 0, ...
$ BsmtHalfBath <int> 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ...
$ FullBath <int> 2, 2, 2, 1, 2, 1, 2, 2, 2, 1, 1, 3, 1, 2, 1, 1, ...
$ HalfBath <int> 1, 0, 1, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, ...
$ BedroomAbvGr <int> 3, 3, 3, 3, 4, 1, 3, 3, 2, 2, 3, 4, 2, 3, 2, 2, ...
$ KitchenAbvGr <int> 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 1, 1, 1, 1, 1, 1, ...
$ KitchenQual <chr> "Gd", "TA", "Gd", "Gd", "Gd", "TA", "Gd", "TA", ...
$ TotRmsAbvGrd <int> 8, 6, 6, 7, 9, 5, 7, 7, 8, 5, 5, 11, 4, 7, 5, 5,...
$ Functional <chr> "Typ", "Typ", "Typ", "Typ", "Typ", "Typ", "Typ",...
$ Fireplaces <int> 0, 1, 1, 1, 1, 0, 1, 2, 2, 2, 0, 2, 0, 1, 1, 0, ...
$ FireplaceQu <chr> NA, "TA", "TA", "Gd", "TA", NA, "Gd", "TA", "TA"...
$ GarageType <chr> "Attchd", "Attchd", "Attchd", "Detchd", "Attchd"...
$ GarageYrBlt <int> 2003, 1976, 2001, 1998, 2000, 1993, 2004, 1973, ...
$ GarageFinish <chr> "RFn", "RFn", "RFn", "Unf", "RFn", "Unf", "RFn",...
$ GarageCars <int> 2, 2, 2, 3, 3, 2, 2, 2, 2, 1, 1, 3, 1, 3, 1, 2, ...
$ GarageArea <int> 548, 460, 608, 642, 836, 480, 636, 484, 468, 205...
$ GarageQual <chr> "TA", "TA", "TA", "TA", "TA", "TA", "TA", "TA", ...
$ GarageCond <chr> "TA", "TA", "TA", "TA", "TA", "TA", "TA", "TA", ...
$ PavedDrive <chr> "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y"...
$ WoodDeckSF <int> 0, 298, 0, 0, 192, 40, 255, 235, 90, 0, 0, 147, ...
$ OpenPorchSF <int> 61, 0, 42, 35, 84, 30, 57, 204, 0, 4, 0, 21, 0, ...
$ EnclosedPorch <int> 0, 0, 0, 272, 0, 0, 0, 228, 205, 0, 0, 0, 0, 0, ...
$ 3SsnPorch <int> 0, 0, 0, 0, 0, 320, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0...
$ ScreenPorch <int> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 176, 0, 0, 0...
$ PoolArea <int> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ...
$ PoolQC <chr> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, ...
$ Fence <chr> NA, NA, NA, NA, NA, "MnPrv", NA, NA, NA, NA, NA,...
$ MiscFeature <chr> NA, NA, NA, NA, NA, "Shed", NA, "Shed", NA, NA, ...
$ MiscVal <int> 0, 0, 0, 0, 0, 700, 0, 350, 0, 0, 0, 0, 0, 0, 0,...
$ MoSold <int> 2, 5, 9, 2, 12, 10, 8, 11, 4, 1, 2, 7, 9, 8, 5, ...
$ YrSold <int> 2008, 2007, 2008, 2006, 2008, 2009, 2007, 2009, ...
$ SaleType <chr> "WD", "WD", "WD", "WD", "WD", "WD", "WD", "WD", ...
$ SaleCondition <chr> "Normal", "Normal", "Normal", "Abnorml", "Normal...
$ SalePrice <int> 208500, 181500, 223500, 140000, 250000, 143000, ...
캐글즐기기 매주 수요일 (파트4 종료, https://github.com/KaggleBreak/analyticstool)
텐서뽀개기 격주 화요일 (6/27일 파트1 시작, https://github.com/KaggleBreak/tensorbreak)